import { deleteByPrimaryKeyForProGroupAuth, selectByPrimaryKeyForProGroupAuth, insertForProGroupAuth, updateForProGroupAuth, deleteByMapForProGroupAuth,updateByMapForProGroupAuth, getOneForProGroupAuth,getAllForProGroupAuth,queryPageForProGroupAuth, countForProGroupAuth, insertBatchForProGroupAuth, deleteBatchForProGroupAuth,updateBatchForProGroupAuth,queryPageForProGroup,getPageProAuthorityByGroupId,queryPageForProAuthChild,getSelectedProAuthByGroupId } from '@/services/system/api_progroupauth';

export default {
    namespace: 'progroupauth',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        group: {
            list: [],
            pagination: {},
        },
        authChild: {
            list: [],
            pagination: {},
        },
        authSelect: {
            list: [],
        },
    },

    effects: {
            *delete_by_primarykey_for_progroupauth({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProGroupAuth, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProGroupAuth',
                    payload: response,
                });
            },
            *select_by_primarykey_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProGroupAuth, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(insertForProGroupAuth, payload);
                yield put({
                    type: 'insertForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(updateForProGroupAuth, payload);
                yield put({
                    type: 'updateForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *delete_by_map_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProGroupAuth, payload);
                yield put({
                    type: 'deleteByMapForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_by_map_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProGroupAuth, payload);
                yield put({
                    type: 'updateByMapForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_one_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProGroupAuth, payload);
                yield put({
                    type: 'getOneForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_all_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProGroupAuth, payload);
                yield put({
                    type: 'getAllForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *count_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(countForProGroupAuth, payload);
                yield put({
                    type: 'countForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_batch_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProGroupAuth, payload);
                yield put({
                    type: 'insertBatchForProGroupAuth',
                    payload: response,
                });
                                
                const responsedata = yield call(queryPageForProGroup, {});
                yield put({
                	type: 'queryPageForProGroup',
                	payload: responsedata,
                });
                
                const newPayload = { group_id: [payload.groupids[0].id]};
                const responseAuth = yield call(getPageProAuthorityByGroupId, newPayload);
                yield put({
                    type: 'getPageProAuthorityByGroupId',
                    payload: responseAuth,
                });
                
                if (callback) callback();
            },
            *delete_batch_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProGroupAuth, payload);
                yield put({
                    type: 'deleteBatchForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_batch_for_progroupauth({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProGroupAuth, payload);
                yield put({
                    type: 'updateBatchForProGroupAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_progroup({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProGroup, payload);
                yield put({
                    type: 'queryPageForProGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_page_proauthority_by_groupid({ payload, callback }, { call, put }) {
                const response = yield call(getPageProAuthorityByGroupId, payload);
                yield put({
                    type: 'getPageProAuthorityByGroupId',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_proauthchild({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProAuthChild, payload);
                yield put({
                    type: 'queryPageForProAuthChild',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_selected_proauth_by_groupid({ payload, callback }, { call, put }) {
                const response = yield call(getSelectedProAuthByGroupId, payload);
                yield put({
                    type: 'getSelectedProAuthByGroupId',
                    payload: response,
                });
                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProGroupAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getPageProAuthorityByGroupId(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProGroup(state, action) {
            return {
                ...state,
                group: action.payload,
            };
        },
        queryPageForProAuthChild(state, action) {
            return {
                ...state,
                authChild: action.payload,
            };
        },
        getSelectedProAuthByGroupId(state, action) {
            return {
                ...state,
                authSelect: action.payload,
            };
        },
    },
};
